<?php

namespace app\api\command;
use app\common\model\Packages;
use app\common\model\UserCommission;
use app\common\model\UserPackagesConfig;
use fast\Random;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Packageslaxin extends Command
{
    protected function configure()
    {
        $this->setName('laxin')->setHelp('产品拉新')->setDescription('产品拉新');

    }

    protected function execute(Input $input, Output $output)
    {
        $url     = config('site.url_172');
        $key     = config('site.key_172');
        $user_id = config('site.zhanghao_172');
        $data['user_id']   = $user_id;
        $data['Timestamp'] = time();
        $data['ProductID'] = '';
        $string = ascll172($data);
        $data['user_sign'] = strtolower(md5($string.$key));
        $url = $url.'/api/order/GetProducts';
        $res = httpPost($url,$data);
        $arr = json_decode($res,true);
        $model = new Packages();
        $num   = 0;
        foreach ($arr['data'] as $k=>$v){
          $count =  $model->where(['platform_type'=>4,'packages_id'=>$v['productID']])->count();
            if(!$count){
                $inser_arr['packages_id']   = $v['productID'];
                $inser_arr['platform_type'] = 4;
                $inser_arr['name']          = $v['productName'];
                $num += $model->insert($inser_arr);
            }
        }
        echo '插入'.$num;
    }
}
